<?php
class NewsController extends FW24H_AppController{
	
	//function index( ) {
	function index( $id='', $cid='') {
		$objModel = new FW24H_Model( 'news', 'ID');
		$v_data = $objModel->find( '', '*', 'ID DESC, Title ASC', 10);
		
		$this->setParam( 'data', $v_data);
		$this->render();
	}

	function beforeFilter() {
		if( $this->actionName == 'ajaxdemo') {
			return true;
		}
		fw24h_useVendor( 'CacheLite', 'links');
		parent::beforeFilter();
		$this->setParam( 'who_r_u', time());
		if( $this->actionName == 'index') {
			$this->setParam( 'where', 'beforeFilter()');
		}
	}

	function afterFilter() {
		//echo $this->actionName;
	}

	function detail( $category_id, $news_id) {
		//$objModel = new FW24H_Model( 'news', 'ID');

		fw24h_useModel( 'news');
		$objModel = new NewsModel();

		$this->setParam( 'news_detail', $objModel->get( $news_id));

		$this->render();
	}

	function cate( $category_id) {
		$objModel = new FW24H_Model( 'category', 'ID');

		$this->setParam( 't_category', $objModel->get( $category_id));
		
		$v_sql = 'SELECT news.ID, Title, SummaryImg, Summary  FROM news, newscategory WHERE news.ID=newscategory.NewsID AND newscategory.CategoryID ='.$category_id.' AND newscategory.Status > 0 ORDER BY newscategory.PublishedDate DESC, newscategory.Status DESC, newscategory.PublishedDate2 DESC LIMIT 10';
		$this->setParam( 't_news', $objModel->execute( $v_sql));

		$this->render();
	}

	function ajaxdemo( $category_id) {
		$objModel = new FW24H_Model( 'category', 'ID');

		$this->setParam( 't_category', $objModel->get( $category_id));
		
		$v_sql = 'SELECT news.ID, Title, SummaryImg, Summary  FROM news, newscategory WHERE news.ID=newscategory.NewsID AND newscategory.CategoryID ='.$category_id.' AND newscategory.Status > 0 ORDER BY newscategory.PublishedDate DESC, newscategory.Status DESC, newscategory.PublishedDate2 DESC LIMIT 10';
		$this->setParam( 't_news', $objModel->execute( $v_sql));

		$this->layout = 'ajax';
		$this->render();
	}
}

